package com.glela.platform.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.glela.common.util.DateUtil;
import com.glela.platform.mapper.CUserRegisterMapper;
import com.glela.platform.model.CUserRegister;
import com.glela.platform.service.UserSignService;

@Service("userSignService")
public class UserSignServiceImpl implements UserSignService {
	@Autowired
	private CUserRegisterMapper userRegisterMapper;
	
	@Override
	public int addUserSignInfo(Long userId, String signCode) {
		String nowDay = DateUtil.currentYourDate("yyyy-MM-dd");
		CUserRegister userRegister = this.userRegisterMapper.selectUserRegister(userId, signCode, nowDay);
		int result = 1;// 1签到成功，2重复签到
		if (userRegister != null) {
			result = 2;
		} else {
			CUserRegister record = new CUserRegister();
			record.setUserId(userId);
			record.setSignCode(signCode);
			record.setSignDay(nowDay);
			record.setCreateTime(new Date());
			this.userRegisterMapper.insertSelective(record);
		}
		return result;
	}

}
